<template>
<div>
  <table>
    <tr>
      <td>标题</td>
      <td>内容</td>
      <td>总评论</td>
      <td>总浏览</td>
      <td>操作</td>
    </tr>
    <tr v-for="i in news">
      <td>{{i.title}}</td>
      <td>{{i.content}}</td>
      <td>{{i.total_comment}}</td>
      <td>{{i.total_views}}</td>
      <td>
        <button @click="comment(i.id)">评论</button>
        <button @click="show(i.id)">查看</button>
        </td>

    </tr>
  </table>
  <button v-for="i in total" @click="get_news(i)">{{i}}</button>

</div>
</template>

<script>
export default {
name: "show_news",
data(){

return{
news:[],
page:1,
total:0,
userid:localStorage.getItem('userid')
}
},
methods:{
get_news(i){
this.$axios.get('/news/news?page='+i)
.then(res=>{
this.news = res.data.list
this.total = res.data.total
})
},
  comment(id){
  if(this.userid){
  this.$router.push({path:'/news_com',query:{'id':id}})
  }
  else {
  alert('未登录')
  this.$router.push('/news_login')
  }

  },
  show(id){
    if(this.userid){
      this.$router.push({path:'/news_info',query:{'id':id}})
    }
    else {
      alert('未登录')
      this.$router.push('/news_login')
    }


  }

},
mounted() {
this.get_news(1)
}
}
</script>

<style scoped>

</style>
